package com.ley.yikang.service.serviceimpl;

import com.ley.yikang.entity.Doctor;
import com.ley.yikang.mapper.DoctorMapper;
import com.ley.yikang.service.DoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DoctorServiceImpl implements DoctorService {
    private final DoctorMapper doctorMapper;

    @Autowired
    public DoctorServiceImpl(DoctorMapper doctorMapper) {
        this.doctorMapper = doctorMapper;
    }

    @Override
    public void addDoctor(Doctor doctor) {
        doctorMapper.addDoctor(doctor);
    }

    @Override
    public List<Doctor> findAll(String doctorName, String phone, Integer communityId) {
        // 使用Map封装可选参数
        Map<String, Object> params = new HashMap<>();
        if (doctorName != null && !doctorName.isEmpty()) {
            params.put("doctorName", doctorName);
        }
        if (phone != null && !phone.isEmpty()) {
            params.put("phone", phone);
        }
        if (communityId != null) {
            params.put("communityId", communityId);
        }
        return doctorMapper.findAll(params);
    }

    @Override
    public Doctor findDoctor(String phone) {
        return doctorMapper.findDoctor(phone);
    }

    @Override
    public Doctor findDoctorById(int id) {
        return doctorMapper.findDoctorById(id);
    }

    @Override
    public void delDoctor(int id) {
        doctorMapper.delDoctor(id);
    }

    @Override
    public void updateDoctor(Doctor doctor) {
        doctorMapper.updateDoctor(doctor);
    }

    @Override
    public List<Doctor> getCommunityDoctor(int communityId) {
        return doctorMapper.getCommunityDoctor(communityId);
    }
}
